<template>
	<web-view v-if="src" :src="src" @message="getMssage" @error="handleError"></web-view>
</template>

<script>
	import {
		uploadFile,
	} from '@/utils/util.js'
	import {
		BASE_URL,
		PYTHON_URL
	} from '@/config/request.js'
	import {
		PrintApi
	} from '@/api'
	export default {
		data() {
			return {
				// 网页地址
				src: null,
			}
		},
		onLoad() {
			this.src = `${BASE_URL}public/mini/cover-preview/#/upload?userId=${this.$store.getters['userInfo'].user_id}`
		},
		methods: {
			/**
			 * @param {Array} e.detail.data 接收的数据
			 */
			async getMssage(e) {
				try {
					this.$showLoading()
					uni.$emit('UploadFileEvent', e.detail.data[0].result)
					console.log('收到网页发来的消息', e.detail.data[0].result);
					uni.hideLoading()
				} catch (err) {
					uni.hideLoading()
					// this.$showToast(err || '上传失败')
				}
			},
			handleError(e) {
				console.log('网页加载失败', e);
				this.$showToast('网页加载失败')
			},
		}
	}
</script>
<style>
	page {
		background-color: #f3f3f3;
	}
</style>
<style scoped lang="scss">
	.list {
		width: 690rpx;
		height: 800rpx;
		margin: 0 auto;
		margin-bottom: 79rpx;

		image {
			width: 100%;
			height: 100%;
		}

		background-color: #fff;
	}
</style>